package service.impl;

import java.util.List;
import java.util.Map;

import dao.DictionaryDao;
import dao.impl.DictionaryDaoImpl;
import entiey.Dictionary;
import entiey.TypeId;
import service.DictionaryService;

public class DictionaryServiceImpl implements DictionaryService {

	DictionaryDao dao=new DictionaryDaoImpl();
	
	@Override
	public boolean saveDictionary(Dictionary d) {
		return dao.add(d)>0;
	}

	@Override
	public boolean updateDictionaryById(Dictionary d) {
		return dao.update(d)>0;
	}

	@Override
	public boolean deleteDictionaryById(int id) {
		return dao.delete(id)>0;
	}

	@Override
	public List<Dictionary> findDictionaryAll() {
		return dao.findAll();
	}

	@Override
	public Dictionary getDictionaryById(int id) {
		return dao.findById(id);
	}

	@Override
	public List<Dictionary> findDictionaryByTypeID(TypeId t) {
		return dao.findDictionaryByTypeID(t.getId());
	}

	@Override
	public boolean adDictionary(TypeId t, String dic) {
		// 查询  判断当前数据库中是否存在指定的内容，如果存在，就不添加
				Dictionary dictionary=dao.getDictionaryByTypeIDAndName(dic, t.getId());
				//数据库不存在
				if (dictionary==null) {
					Dictionary d=new Dictionary();
					d.setName(dic);
					d.setTypeid(t);
					return saveDictionary(d);
				}
				return false;
	}

	@Override
	public Map<String, String> getMapByJson(String code) {
		return null;
	}

	@Override
	public Dictionary getDictionaryByTypeIDAndName(String name, TypeId tid) {
		return dao.getDictionaryByTypeIDAndName(name, tid.getId());
	}

}
